﻿<Window x:Class="WindowsUpdateNotifier.PopupView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:app="clr-namespace:WindowsUpdateNotifier" 
        Title="Popup" 
        WindowStartupLocation="Manual"
        Height="70" 
        Width="300" 
        SnapsToDevicePixels="False"
        ShowInTaskbar="False" 
        Topmost="True" 
        WindowStyle="None" 
        AllowsTransparency="True"
        app:WindowBehavior.BackgroundClickCommand="{Binding OnOpenWindowsUpdateControlPanelCommand}">
    
    <Window.DataContext>
        <app:PopupViewModel Title="Windows Updates Available"
            BackgroundColor="#FF232627"
            ShowUpdateIcon="True"
            Message="33 updates are available."/>
    </Window.DataContext>

    <Window.Resources>
        <app:VisibleWhenTrueConverter x:Key="VisibleWhenTrueConverter"/>
        <app:VisibleWhenFalseConverter x:Key="VisibleWhenFalseConverter"/>
    </Window.Resources>
    
    <Window.Triggers>
        <EventTrigger RoutedEvent="Window.Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard TargetProperty="Opacity" app:DataTriggerBehavior.StoryboardCompletedCommand="{Binding OnCloseCommand}">
                        <DoubleAnimation From="0" To="1" Duration="0:0:2"/>
                        <DoubleAnimation From="0.97" To="0" Duration="0:0:2" BeginTime="0:0:15"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Window.Triggers>

    <Border Background="{Binding BackgroundColor}" Name="Root">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="60"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            
            <Grid Margin="14">
                <Path Data="M12,1L3,5V11C3,16.55 6.84,21.74 12,23C17.16,21.74 21,16.55 21,11V5L12,1Z"
                      Stretch="Uniform" Fill="#FFFFFF"  />

                <Path Data="F1 M 23.7501,33.25L 34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z"
                      Stretch="Uniform" Fill="{Binding BackgroundColor}" Margin="6" 
                      Visibility="{Binding ShowUpdateIcon, Converter={StaticResource VisibleWhenFalseConverter}}"/>

                <Path Data="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"
                      Stretch="Uniform" Fill="{Binding BackgroundColor}" Margin="7" 
                      Visibility="{Binding ShowUpdateIcon, Converter={StaticResource VisibleWhenTrueConverter}}"/>
            </Grid>

            <DockPanel Grid.Column="1" Margin="10" LastChildFill="True">
                <Label Content="{Binding Title}" Foreground="#FFFFFF" FontSize="14" FontWeight="Bold" FontFamily="Calibri" Padding="0"
                       DockPanel.Dock="Top"/>

                <Label Foreground="#FFFFFF" FontFamily="Calibri" FontSize="14" FontWeight="Light" Opacity="0.6" 
                       VerticalContentAlignment="Top" Padding="0" DockPanel.Dock="Top">
                    
                    <TextBlock Text="{Binding Message}" TextWrapping="Wrap" VerticalAlignment="Top"/>
                </Label>
            </DockPanel>

            <Button Grid.Column="1" Width="20" Height="20" BorderThickness="0" Margin="0,5,5,0" 
                    Command="{Binding OnCloseCommand}" HorizontalAlignment="Right" VerticalAlignment="Top"
                    Visibility="{Binding IsMouseOver, ElementName=Root, Converter={StaticResource VisibleWhenTrueConverter}}">

                <Button.Template>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="border" BorderThickness="0" Background="#00000000" BorderBrush="#C3C3C3">
                            <Path Data="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z"
                                            Stretch="Uniform" Fill="#FFFFFF" Width="11" Height="11" />
                        </Border>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Opacity" Value="0.5" />
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Opacity" Value="0.2" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Button.Template>
            </Button>
        </Grid>
    </Border>
</Window>
